home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / maximus / mul100.zip / MORSE.SCR < prev    next >
Text File  |  1993-02-01  |  5KB  |  134 lines

  1.  
  2. // MORSE.SCR  --  Play command line text in Morse Code  --  Version 1.00
  3. //
  4. // Script program for MUL - the Maximus User Language
  5. // MUL is (C) Copyright 1990-93 by CodeLand Australia
  6. //
  7. // Based on code written by Michael M. Dodd, N4CF, and placed in the public
  8. // domain. Modified for ZTC++, TC++, & BC++ by Bob Stout.
  9. //
  10. // USAGE:       MUL -pMorse "String to play"
  11.  
  12. char *banner = "MORSE v1.00";               // Script banner
  13. char *desc = "Play Text in Morse Code";     // Description
  14. int note = 1500;                            // Note to play
  15. int dely = 54;                              // Timing delay
  16. char line[128];                             // Line to play
  17. int SPACE_MASK = 0x8000;                    // Bit mask
  18. int BIT_MASK = 0xFE;                        // Bit mask
  19.  
  20. int codes[64] = {                           // Morse codes
  21.     0x8000,                                 // Entry 0 = space (0x20)
  22.     0, 0, 0, 0, 0, 0, 0, 0,                 // ! " # $  % & " (
  23.     0, 0, 0, 115, 49, 106, 41,              // ) * + , - . /
  24.     63, 62, 60, 56, 48, 32, 33, 35,         // 0 1 2 3 4 5 6 7
  25.     39, 47, 0, 0, 0, 0, 0, 76,              // 8 9 : ; < = > ?
  26.     0, 6, 17, 21, 9, 2, 20, 11,             // @ A B C D E F G
  27.     16, 4, 30, 13, 18, 7, 5, 15,            // H I J K L M N O
  28.     22, 27, 10, 8, 3, 12, 24, 14,           // P Q R S T U V W
  29.     25, 29, 19                              // X Y Z
  30. };
  31.  
  32. // Main program
  33. main (int argc, char *a1, char *a2, char *a3, char *a4, char *a5, char *a6)
  34. {
  35.     printf ("\n%s - %s\n\n",banner,desc);   // Announce
  36.     getcmd (argc,a1,a2,a3,a4,a5,a6);        // Get the command line
  37.  
  38.     printf ("Playing text: ");
  39.     morse (line);                           // Play the text
  40.  
  41.     saybibi ();                             // Was it good for you too?
  42. }
  43.  
  44. // The Morse code pattern is taken from bit 0, and is shifted right each
  45. // time an element is sent.  A special "marker bit" follows the complete
  46. // Morse pattern.  This marker bit is tested before transmitting each bit;
  47. // if there are no 1's in bits 1..15, the complete character has been sent.
  48. // For example, an "L" would be 0000000000010010, with bit zero containing
  49. // the first dot, bit one the dash, etc.  The marker bit is in bit 4.
  50.  
  51. // Morse code function
  52. morse (char *cp)
  53. {  
  54.     int ch, c;
  55.  
  56.     while ((c=ch=*cp++)!=0) {               // Transmit complete string
  57.  
  58.         ch=toupper (ch);                    // No lower-case characters
  59.         ch=ch-' ';                          // Adjust for zero-based table
  60.         if (ch>=0&&ch<=58) {                // If out of range, ignore it
  61.             ch=codes[ch];                   // Look up Morse pattern from table
  62.             if (And (ch,SPACE_MASK)) {      // If the space bit is set
  63.                 putch (' ');                // Echo the character to screen
  64.                 word_space ();
  65.             }
  66.             else {
  67.                 putch (c);                  // Echo the character to screen
  68.                 while (And (ch,BIT_MASK)) { // Transmit one character
  69.                   if (And (ch,1))
  70.                       send_dash ();         // Sound a dash
  71.                   else
  72.                       send_dot ();          // Sound a dot
  73.                   ch=ShiftRight (ch,1);     // Bitwise shift right
  74.                 }
  75.                 ltr_space ();               // Send a space following character
  76.             }
  77.         }
  78.     }
  79.     putch ('\n');                           // Terminate screen line
  80. }
  81.  
  82. // Send a dot and a space
  83. send_dot ()
  84. {
  85.     Play (note,dely);                       // Play the note
  86.     Play (0,dely);                          // Pause
  87. }
  88.  
  89. // Send a dash and a space
  90. send_dash ()          
  91. {
  92.     Play (note,3*dely);                     // Play the note
  93.     Play (0,dely);                          // Pause
  94. }
  95.  
  96. // Produce a letter space
  97. ltr_space ()          
  98. {
  99.     Play (0,2*dely);                       // Pause * 2
  100. }
  101.  
  102. // Produce a word space
  103. word_space ()         
  104. {
  105.     Play (0,4*dely);                       // Pause * 4
  106. }
  107.  
  108. // Get the command line
  109. getcmd (int count, char *a1, char *a2, char *a3, char *a4, char *a5, char *a6)
  110. {
  111.     // Load command line text to play
  112.  
  113.     if (count) {
  114.         strcpy (line,a1);
  115.         if(--count>0) { strcat (line," "); strcat (line,a2); }
  116.         if(--count>0) { strcat (line," "); strcat (line,a3); }
  117.         if(--count>0) { strcat (line," "); strcat (line,a4); }
  118.         if(--count>0) { strcat (line," "); strcat (line,a5); }
  119.         if(--count>0) { strcat (line," "); strcat (line,a6); }
  120.     }
  121.  
  122.     // If nothing entered on command line use default
  123.     if(!line[0]) strcpy (line,"Enter text on command line");
  124. }
  125.  
  126. // Byebye
  127. saybibi ()
  128. {                             
  129.     puts ("\nMorse done!\n");
  130. }
  131.  
  132. // End of script
  133.  
  134.